package com.magina.mq.rabbit.exchange.topic;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 文件名称：LogErrorReceiver</br>
 * 初始作者： Magina.Hu</br>
 * 创建日期： 2019/5/10</br>
 * 功能说明： Exchange 将RouteKey 和某Topic 进行模糊匹配
 *          匹配到*.log.error 的key都能消费消息<br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2019-2020 .All rights reserved.<br/>
 */
@Component
@Slf4j
@RabbitListener(
        bindings=@QueueBinding(
                value = @Queue(value = "${rab.mq.config.queue.error}",autoDelete="true"),
                exchange =@Exchange(value = "${rab.mq.config.exchange}",type =ExchangeTypes.TOPIC),
                key = "*.log.error"
        )
)
public class LogErrorReceiver {

    @Value("${rab.mq.config.queue.error}")
    private String errorTopicQueueName;

    @RabbitHandler
    public void process(String msg){
        String resultStr  = "RabbitMq:"+errorTopicQueueName+" consumer 收到一条信息: " + msg;
        System.out.println( resultStr);
    }
}
